<%@ include file="includes.jsp" %>

 <script type="text/javascript">
 <!--

     var teamID = null, 
         taskID = null;
 
     $(document).ready(function() {
          $("#proto").dblclick(function(event) {
	           var thisCell, tgt = $(event.target);
	           if (tgt.is('td')) {
	        	   thisCell = tgt;
	           } else if (tgt.parents('td').length) {
	        	   thisCell = tgt.parents('td:first');
	           }
	           if (thisCell.hasClass("tsk-marker")) {
                   showDlg(thisCell.attr("id"), "taskDlg", "task_dlg.htm");
	           } else if (thisCell.hasClass("tm-marker")) {
	        	   showDlg(thisCell.attr("id"), "teamDlg", "team_dlg.htm");
	           }
	           return false;
           });
     });

     function showDlg(id, formID, url) {
         $("#" + formID).load(url, 'id=' + id, function(responseText, textStatus, XMLHttpRequest) {
         	addHoverListeners();
             $("#" + $(this).attr("id")).dialog({
                     bgiframe: true,
                     width: 'auto',
                     modal: true,
                     title: $("#dlg_title").val(),
                     buttons: {
                          "OK": function() {
                              $(this).dialog('close');
                          }
                     },
                     open: function () {
                     	addHoverListeners();
                     	$(document).find(".ui-dialog-buttonpane > :button").each(function(i) {this.focus();});            
                     },
                     close: function() {
                                 $(this).dialog('destroy');
                            }    
                     });
         });
     }

    function setStartTime() {
        $("#time_control").load('start_at_time.htm #time_control', { start_time: $("#start_time").val() });
        return false;
     }

     function setStopTime() {
        $("#time_control").load('stop_at_time.htm #time_control', { stop_time: $("#stop_time").val() });
        return false;
     }

     function changeTaskState(id) {
     	return dlgAction("taskDlg", "ch_enable.htm", {id: id});
     }

     function changeTeamState(id) {
     	return dlgAction("teamDlg", "block_team.htm", {id: id});
     }

     function extTryGuess(id, taskID) {
     	return dlgAction("teamDlg", "ext_try.htm", {guess: $("#guess").val(), id: id, taskID: taskID});
     }

     function doReject() {
         dlgAction("teamDlg", "ext_reject.htm", {id: teamID, taskID: taskID});
         teamID = null;
         taskID = null;
     }
     
     function extReject(id, localTaskID) {
         teamID = id;
         taskID = localTaskID;
         return showConfDlg(doReject);
     }

     function dlgAction(container, url, params) {
     	$("#" + container).load(url, params, function (responseText, textStatus, XMLHttpRequest) {
                    addHoverListeners();
                    $("#proto").load('home.htm #proto');
                    });
         return false;
     }


     $(document).ready(function() {
    	    setInterval(function() {
    	        $("#proto").load('home.htm #proto');
   	        }, 60000);
     });

 //-->
 </script>

<div id="time_control" style="height: 72px; margin-bottom: -10px">
    <form action="start_at_time.htm" id="startForm" style="text-align: left; float: left; width: 50%;">
        <table>
            <tr><td colspan="3">
                    <c:if test="${gameContext.new}">
                        <c:if test="${! empty gameContext.start}">
                            <spring:message code="messages.control_center.game_will_start"/>
                            &nbsp;<b><joda:format value="${gameContext.start}" pattern="HH:mm"/></b><br>
                            <tr><td>
                            <input type="text" id="start_time" value="<joda:format value="${gameContext.start}" pattern="HH:mm"/>">
                        </c:if>
	                    <c:if test="${empty gameContext.start}">
	                        <spring:message code="messages.control_center.start_time_not_set"/><br>
	                        </td></tr>
	                        <tr><td>
	                        <input type="text" id="start_time" value="<spring:message code="messages.control_center.default_start_time"/>">           
	                   </c:if>
			           <td>
			               <button type="button" class="btn" onclick="setStartTime();">
			                   <spring:message code="messages.control_center.set_time"/>
			               </button>
			           </td>
		               <td>
                           <button type="button" class="btn" onclick="this.form.action = 'start_game.htm'; this.form.submit()">
                               <spring:message code="messages.control_center.go"/>
                           </button>
		               </td>
                    </c:if>
                    <c:if test="${!gameContext.new}">
                        <td>
                            <spring:message code="messages.control_center.game_started"/>
                                &nbsp;<b><joda:format value="${gameContext.start}" pattern="HH:mm"/></b>
                        </td>
                        <c:if test="${gameContext.finished}">
                            <td>
                                <button type="button" class="btn" onclick="this.form.action = 'new_game.htm'; this.form.submit()">
                                    <spring:message code="messages.control_center.new"/>
                                </button>
                            </td>                      
                        </c:if>
                    </c:if>
         </table>
    </form>
    
    <form action="stop_at_time.htm" id="stopForm" style="text-align: left; float: left; width: 50%;">
        <table>
            <tr><td colspan="3">
                <c:if test="${!gameContext.finished}">
				    <c:if test="${! empty gameContext.end}">
					   <spring:message code="messages.control_center.game_will_stop"/>
						  &nbsp;<b><joda:format value="${gameContext.end}" pattern="HH:mm"/></b><br>
                       </td></tr>
                       <tr><td>
					   <input type="text" id="stop_time" value="<joda:format value="${gameContext.end}" pattern="HH:mm"/>">
					</c:if>
					<c:if test="${empty gameContext.end}">
					   <spring:message code="messages.control_center.stop_time_not_set"/><br>
                       </td></tr>
                       <tr><td>
						<input type="text" id="stop_time" value="<spring:message code="messages.control_center.default_stop_time"/>">           
					</c:if>

				    <td>
                        <button type="button" class="btn" onclick="setStopTime();">
                               <spring:message code="messages.control_center.set_time"/>
                        </button>
					</td><td>
					<c:if test="${gameContext.started}">
                        <button type="button" class="btn" onclick="this.form.action = 'stop_game.htm'; this.form.submit()">
                            <spring:message code="messages.control_center.stop"/>
                        </button>
				    </c:if>
                </c:if>
                <c:if test="${gameContext.finished}">
                    <div style="padding: 7px 0px 0px 0px">
                        <spring:message code="messages.control_center.game_finished"/>
                            &nbsp;<b><joda:format value="${gameContext.end}" pattern="HH:mm"/></b><br/>
                    </div>
                </c:if>
            </td></tr>
	    </table>
    </form>
</div>

<hr style="background-color:#4297D7; margin-bottom: 15px; margin-left: 5px;"/>

<div id="proto_place" style="display: block; float: left;">
    <jsp:include page="proto.jsp"/>
</div>

<div style="display: none;">
    <div id="obtainedTaskDlg" title="">
        <div>
        </div>
    </div>
    <div id="teamDlg" title="">
        <div>
        </div>
    </div>
    <div id="taskDlg">
    </div>
</div>

